package mystia.lorelei.app.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import mystia.lorelei.app.entity.Member;
import mystia.lorelei.app.service.MemberService;
import mystia.lorelei.app.util.Result;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;

import java.util.List;

/**
 * 会员表(Member)表控制层
 *
 * @author gy_fangtao
 * @since 2023-09-16 16:07:02
 */
@RestController
@RequestMapping("/member")
@Tag(name = "会员管理")
public class MemberController {
	/**
	 * 服务对象
	 */
	@Resource
	private MemberService memberService;
	
	@PostMapping("/save")
	@Operation(summary = "保存会员")
	public Result saveMember(@RequestBody Member member) {
		memberService.saveMember(member);
		return Result.ok();
	}
	
	@GetMapping("/query/{id}")
	@Operation(summary = "获取会员")
	public Result<Member> queryMember(@PathVariable("id") int id) {
		return Result.ok(memberService.queryMemberById(id));
	}
	
	@DeleteMapping("/delete/{id}")
	@Operation(summary = "删除会员")
	public Result deleteMember(@PathVariable("id") int id) {
		memberService.deleteMember(id);
		return Result.ok();
	}
	
	@DeleteMapping("/delete")
	@Operation(summary = "批量删除会员")
	public Result deleteMembers(@RequestBody List<Integer> ids) {
		try {
			memberService.deleteMembers(ids);
			return Result.ok();
		} catch (Exception e) {
			return Result.fail();
		}
	}
	
	@GetMapping("/list")
	@Operation(summary = "批量获取")
	public Result<List<Member>> listMember() {
		return Result.ok(memberService.listMembers());
	}
}


